package com.van.stockanalysis.service;

import java.io.IOException;
import java.io.InputStream;

import org.apache.ibatis.io.Resources;
import org.apache.ibatis.session.SqlSession;
import org.apache.ibatis.session.SqlSessionFactory;
import org.apache.ibatis.session.SqlSessionFactoryBuilder;

import com.van.stockanalysis.dao.UserDao;
import com.van.stockanalysis.pojo.User;

public class SelectService {
	public static User select(String username){
		String source = "mybatis-config.xml";
		InputStream input = null;
		try {
			input = Resources.getResourceAsStream(source);
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		SqlSessionFactory factory =new SqlSessionFactoryBuilder().build(input);
		SqlSession session = factory.openSession();
		
		UserDao userDao = session.getMapper(UserDao.class);
		User user = userDao.selectByUserName(username);
		if(user != null){
			return user;
		}
		session.commit();
		session.close();
		return null;
	}
}
